var streamSources = new Array();
$(document).on('click', '.btn-add-source', function(event) {
    var textBox = $('#c2101_url');
    var expression = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi;
    var regex = new RegExp(expression);
    source = textBox.val();
    if (source.match(regex) && streamSources.indexOf(source) == -1) {
        sourceTitle = "Link title";
        sourceLink = source;
        $('.additional-sources-container .blank-state').css('display', 'none');
        $('.additional-sources-container ul.items').append(
                "<li>\
                    <strong>" + sourceTitle + "</strong><a class=\"removeSource\">remove</a>\
                    <br><a href=" + sourceLink + ">" + sourceLink + "</a>\
                </li>"
                );
        streamSources.push(source);
    }
    else {
        textBox.css('border-color', 'red');
        setTimeout(function(e) {
            textBox.css('border-color', '');
        }, 2000);
    }
});

$(document).on('click', 'ul.items li a.removeSource', function(event) {
    remove_item(streamSources, $(this).next().next().attr('href'));
    $(this).parent().remove();
});

remove_item = function(arr,value){
    for(b in arr ){
        if(arr[b] == value){
            arr.splice(b,1);
            break;
        }
    }
    return arr;
}